package com.magic.smartcity.view.more.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.magic.smartcity.R
import com.magic.smartcity.beans.MetroStepList
import com.magic.smartcity.databinding.ItemMetroAllLinesBinding

/**
 * @description:
 * @create: Create by Magic on 2022/2/14.
 */
class MetroHomeAllLineStepAdapter : RecyclerView.Adapter<MetroHomeAllLineStepAdapter.ItemHolder>() {
    private val TAG: String = "MetroHomeAllLineStepAdapter"
    private val lines: MutableList<MetroStepList> = mutableListOf()
    private lateinit var runStationName: String
    fun setData(list: List<MetroStepList>,runStationName:String){
        lines.clear()
        lines.addAll(list/*.sortedBy { it.seq }*/)
        this.runStationName = runStationName
        notifyDataSetChanged()
    }

    class ItemHolder(binding: ItemMetroAllLinesBinding ) : RecyclerView.ViewHolder(binding.root) {
        val binding = binding
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        var binding = DataBindingUtil.inflate<ItemMetroAllLinesBinding>(
            LayoutInflater.from(parent.context),
            R.layout.item_metro_all_lines,
            parent,
            false
        )
        return ItemHolder(binding)
    }

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.binding.step = lines[position]
        holder.binding.runStationName = runStationName
    }

    override fun getItemCount()=lines.size
}